package client;

import beans.Estudiant;
import beans.ParticipacioEnquesta;
import beans.PreguntaEnquesta;
import common.EOlympicsException;
import common.RemotInterface;
import common.TDSLanguageUtils;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 * Classe PantallaParticipacio
 * @author Juan Luís Chávez Lobato i Jesús Hernàndez Garcia
 */

public class PantallaParticipacio extends javax.swing.JFrame {
    
    private RemotInterface remot;
    private Estudiant EstLogin;
    private int numPregunta[];
    
    /**
     * Creates new form PantallaParticipacio
     */
    public PantallaParticipacio(RemotInterface rem, Estudiant est) {
        
          try {
            remot = rem;
            EstLogin = est;
            TDSLanguageUtils.setDefaultLanguage("i18n/messages");
            initComponents();
            
            numPregunta = new int[8];
            
            ComboPreg1.setVisible(false);
            ComboPreg2.setVisible(false);
            ComboPreg3.setVisible(false);
            ComboPreg4.setVisible(false);
            ComboPreg5.setVisible(false);
            ComboPreg6.setVisible(false);
            ComboPreg7.setVisible(false);
            ComboPreg8.setVisible(false);
            LabPreg1.setVisible(false);
            LabPreg2.setVisible(false);
            LabPreg3.setVisible(false);
            LabPreg4.setVisible(false);
            LabPreg5.setVisible(false);
            LabPreg6.setVisible(false);
            LabPreg7.setVisible(false);
            LabPreg8.setVisible(false);

            setTitle(TDSLanguageUtils.getMessage("titol.finestra"));
            BotoEnviar.setText(TDSLanguageUtils.getMessage("boto.enviar"));
            BotoCancelar.setText(TDSLanguageUtils.getMessage("boto.cancelar"));
            LabelNomEst.setText(TDSLanguageUtils.getMessage("texte.NomEst"));
            LabelNomUniv.setText(TDSLanguageUtils.getMessage("texte.NomUniv"));
            NomEstudiant.setText(EstLogin.getNom() + " " + EstLogin.getCognoms());
            NomUniversitat.setText(remot.getNomUniversitat(EstLogin.getIdUni()));

            List<PreguntaEnquesta> pregEnq = remot.getPreguntesEnquesta();

            if (pregEnq.isEmpty()) {
                // L'enquesta no té preguntes 
                throw new EOlympicsException(TDSLanguageUtils.getMessage("missatge.nohihapre"));
            } else if (pregEnq.size() > 8) {     
                // L'enquesta té més preguntes de les que es poden gestionar
                throw new EOlympicsException(TDSLanguageUtils.getMessage("missatge.massapre"));
            } else {
                int npreg = 1;
                // Muntar els labels i combos de les preguntes. Aquestes venen
                // per ordre de número.
                for (PreguntaEnquesta preg : pregEnq) {
                    switch (npreg) {
                        case 1:
                            LabPreg1.setText(preg.getTexte());
                            LabPreg1.setVisible(true);
                            carregarCombo(ComboPreg1);
                            ComboPreg1.setVisible(true);
                            break;
                        case 2:
                            LabPreg2.setText(preg.getTexte());
                            LabPreg2.setVisible(true);
                            carregarCombo(ComboPreg2);
                            ComboPreg2.setVisible(true);
                            break;
                        case 3:
                            LabPreg3.setText(preg.getTexte());
                            LabPreg3.setVisible(true);
                            carregarCombo(ComboPreg3);
                            ComboPreg3.setVisible(true);
                            break;
                        case 4:
                            LabPreg4.setText(preg.getTexte());
                            LabPreg4.setVisible(true);
                            carregarCombo(ComboPreg4);
                            ComboPreg4.setVisible(true);
                            break;
                        case 5:
                            LabPreg5.setText(preg.getTexte());
                            LabPreg5.setVisible(true);
                            carregarCombo(ComboPreg5);
                            ComboPreg5.setVisible(true);
                            break;
                        case 6:
                            LabPreg6.setText(preg.getTexte());
                            LabPreg6.setVisible(true);
                            carregarCombo(ComboPreg6);
                            ComboPreg6.setVisible(true);
                            break;
                        case 7:
                            LabPreg7.setText(preg.getTexte());
                            LabPreg7.setVisible(true);
                            carregarCombo(ComboPreg7);
                            ComboPreg7.setVisible(true);
                            break;
                        case 8:
                            LabPreg8.setText(preg.getTexte());
                            LabPreg8.setVisible(true);
                            carregarCombo(ComboPreg8);
                            ComboPreg8.setVisible(true);
                            break;
                    }
                    // Guardem el número de pregunta per a després gravar l'enquesta
                    numPregunta[npreg-1] = preg.getNum();
                    npreg++;
                }
            }
            
        } catch (RemoteException ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog
                    (null, TDSLanguageUtils.getMessage("ERR_REMOT"), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (EOlympicsException ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BotoEnviar = new javax.swing.JButton();
        BotoCancelar = new javax.swing.JButton();
        PanellEstudiant = new javax.swing.JPanel();
        LabelNomEst = new javax.swing.JLabel();
        LabelNomUniv = new javax.swing.JLabel();
        NomEstudiant = new javax.swing.JLabel();
        NomUniversitat = new javax.swing.JLabel();
        PanellPreguntes = new javax.swing.JPanel();
        LabPreg1 = new javax.swing.JLabel();
        LabPreg2 = new javax.swing.JLabel();
        LabPreg3 = new javax.swing.JLabel();
        LabPreg4 = new javax.swing.JLabel();
        LabPreg5 = new javax.swing.JLabel();
        LabPreg6 = new javax.swing.JLabel();
        LabPreg7 = new javax.swing.JLabel();
        ComboPreg1 = new javax.swing.JComboBox();
        ComboPreg2 = new javax.swing.JComboBox();
        ComboPreg3 = new javax.swing.JComboBox();
        ComboPreg4 = new javax.swing.JComboBox();
        ComboPreg5 = new javax.swing.JComboBox();
        ComboPreg6 = new javax.swing.JComboBox();
        ComboPreg7 = new javax.swing.JComboBox();
        LabPreg8 = new javax.swing.JLabel();
        ComboPreg8 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        BotoEnviar.setText("Enviar enquesta");
        BotoEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotoEnviarActionPerformed(evt);
            }
        });

        BotoCancelar.setText("Cancel·lar");
        BotoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotoCancelarActionPerformed(evt);
            }
        });

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("i18n/messages"); // NOI18N
        PanellEstudiant.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("panell.EstConn"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        PanellEstudiant.setFocusable(false);

        LabelNomEst.setText("Nom i cognoms :");

        LabelNomUniv.setText("Universitat :");

        NomEstudiant.setBackground(new java.awt.Color(0, 204, 204));
        NomEstudiant.setText("Nom Estudiant");
        NomEstudiant.setOpaque(true);

        NomUniversitat.setBackground(new java.awt.Color(0, 204, 204));
        NomUniversitat.setText("Nom Universitat");
        NomUniversitat.setOpaque(true);

        javax.swing.GroupLayout PanellEstudiantLayout = new javax.swing.GroupLayout(PanellEstudiant);
        PanellEstudiant.setLayout(PanellEstudiantLayout);
        PanellEstudiantLayout.setHorizontalGroup(
            PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanellEstudiantLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LabelNomEst)
                    .addComponent(LabelNomUniv))
                .addGap(18, 18, 18)
                .addGroup(PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NomEstudiant, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(NomUniversitat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        PanellEstudiantLayout.setVerticalGroup(
            PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanellEstudiantLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabelNomEst)
                    .addComponent(NomEstudiant))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanellEstudiantLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabelNomUniv)
                    .addComponent(NomUniversitat))
                .addContainerGap())
        );

        PanellPreguntes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("panell.preguntes"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        LabPreg1.setLabelFor(ComboPreg1);
        LabPreg1.setText("Pregunta 1");
        LabPreg1.setNextFocusableComponent(ComboPreg1);

        LabPreg2.setLabelFor(ComboPreg2);
        LabPreg2.setText("Pregunta 2");
        LabPreg2.setNextFocusableComponent(ComboPreg2);

        LabPreg3.setLabelFor(ComboPreg3);
        LabPreg3.setText("Pregunta 3");
        LabPreg3.setNextFocusableComponent(ComboPreg3);

        LabPreg4.setText("Pregunta 4");
        LabPreg4.setNextFocusableComponent(ComboPreg4);

        LabPreg5.setText("Pregunta 5");
        LabPreg5.setNextFocusableComponent(ComboPreg5);

        LabPreg6.setText("Pregunta 6");
        LabPreg6.setNextFocusableComponent(ComboPreg6);

        LabPreg7.setText("Pregunta 7");

        ComboPreg1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        ComboPreg7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        LabPreg8.setText("Pregunta 8");

        ComboPreg8.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout PanellPreguntesLayout = new javax.swing.GroupLayout(PanellPreguntes);
        PanellPreguntes.setLayout(PanellPreguntesLayout);
        PanellPreguntesLayout.setHorizontalGroup(
            PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanellPreguntesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanellPreguntesLayout.createSequentialGroup()
                        .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LabPreg1)
                            .addComponent(LabPreg2)
                            .addComponent(LabPreg3)
                            .addComponent(LabPreg4)
                            .addComponent(LabPreg5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(ComboPreg5, 0, 266, Short.MAX_VALUE)
                            .addComponent(ComboPreg4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(ComboPreg3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(ComboPreg2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(ComboPreg1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(PanellPreguntesLayout.createSequentialGroup()
                        .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PanellPreguntesLayout.createSequentialGroup()
                                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(LabPreg6)
                                    .addComponent(LabPreg7))
                                .addGap(93, 93, 93)
                                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(ComboPreg6, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(ComboPreg7, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(PanellPreguntesLayout.createSequentialGroup()
                                .addComponent(LabPreg8)
                                .addGap(93, 93, 93)
                                .addComponent(ComboPreg8, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        PanellPreguntesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {ComboPreg1, ComboPreg2, ComboPreg3, ComboPreg4, ComboPreg5, ComboPreg6, ComboPreg7});

        PanellPreguntesLayout.setVerticalGroup(
            PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanellPreguntesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg5))
                .addGap(12, 12, 12)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabPreg6)
                    .addComponent(ComboPreg6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanellPreguntesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboPreg8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabPreg8))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PanellEstudiant, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BotoEnviar, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BotoCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(PanellPreguntes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanellEstudiant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(PanellPreguntes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BotoEnviar)
                    .addComponent(BotoCancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotoCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_BotoCancelarActionPerformed

    private void BotoEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotoEnviarActionPerformed
        dispose();
        List<ParticipacioEnquesta> resultats = 
                new ArrayList<ParticipacioEnquesta>();
        
        // A traves del numero de pregunta que hem guardat al carregar, gravem
        // les diferents preguntes contestades per l'estudiant.
        for (int i = 0; i <= 7; i++) {
            // si numPregunta = 0, vol dir que no s'ha carregat el combo corresponent
            if (numPregunta[i] != 0) {
                switch (i) {
                    case 0:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg1.getSelectedIndex(), new Date()));
                        break;
                    case 1:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg2.getSelectedIndex(), new Date()));
                        break;
                    case 2:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg3.getSelectedIndex(), new Date()));
                        break;
                    case 3:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg4.getSelectedIndex(), new Date()));
                        break;
                    case 4:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg5.getSelectedIndex(), new Date()));
                        break;
                    case 5:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg6.getSelectedIndex(), new Date()));
                        break;
                    case 6:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg7.getSelectedIndex(), new Date()));
                        break;
                    case 7:
                        resultats.add(new ParticipacioEnquesta(EstLogin.getLogin(),
                                numPregunta[i], ComboPreg8.getSelectedIndex(), new Date()));
                        break;

                }
            }

        }
                
        try{
            boolean isOk = remot.guardarRespostesEnquesta(resultats);
            if (isOk) {
                JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("missatge.enquFinal"),
                        EstLogin.getNom() + " " + EstLogin.getCognoms(),
                        JOptionPane.INFORMATION_MESSAGE);

                new PantallaResultats(remot, EstLogin).setVisible(true);
            }else{
                throw new EOlympicsException(TDSLanguageUtils.getMessage("missatge.errorGuardant"));
            }
        } catch (RemoteException ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog
                    (null, TDSLanguageUtils.getMessage("ERR_REMOT"), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (EOlympicsException ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception ex) {
            Logger.getLogger(PantallaParticipacio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_BotoEnviarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        dispose();
    }//GEN-LAST:event_formWindowClosing

    // Carrega un combo d'una pregunta amb les respostes possibles
    private void carregarCombo(JComboBox combo) {
        combo.removeAllItems();
        for (int i = 0; i <= 4; i++) {
            combo.addItem(TDSLanguageUtils.getMessage("combo.op" + i));
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PantallaParticipacio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PantallaParticipacio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PantallaParticipacio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PantallaParticipacio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
//                new PantallaParticipacio().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotoCancelar;
    private javax.swing.JButton BotoEnviar;
    private javax.swing.JComboBox ComboPreg1;
    private javax.swing.JComboBox ComboPreg2;
    private javax.swing.JComboBox ComboPreg3;
    private javax.swing.JComboBox ComboPreg4;
    private javax.swing.JComboBox ComboPreg5;
    private javax.swing.JComboBox ComboPreg6;
    private javax.swing.JComboBox ComboPreg7;
    private javax.swing.JComboBox ComboPreg8;
    private javax.swing.JLabel LabPreg1;
    private javax.swing.JLabel LabPreg2;
    private javax.swing.JLabel LabPreg3;
    private javax.swing.JLabel LabPreg4;
    private javax.swing.JLabel LabPreg5;
    private javax.swing.JLabel LabPreg6;
    private javax.swing.JLabel LabPreg7;
    private javax.swing.JLabel LabPreg8;
    private javax.swing.JLabel LabelNomEst;
    private javax.swing.JLabel LabelNomUniv;
    private javax.swing.JLabel NomEstudiant;
    private javax.swing.JLabel NomUniversitat;
    private javax.swing.JPanel PanellEstudiant;
    private javax.swing.JPanel PanellPreguntes;
    // End of variables declaration//GEN-END:variables
}
